home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / gms_dev.lha / GMSDev / Source / C / Misc / Colours.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-06  |  4.2 KB  |  143 lines

  1. /* Dice: 1> dcc -l0 -mD dpk.o tags.o Colours.c -o Colours
  2. **
  3. ** This source demonstrates use of the Colours module.
  4. */
  5.  
  6. #include <proto/dpkernel.h>
  7. #include <clib/colours_protos.h>
  8.  
  9. BYTE *ProgName      = "Colours Demo";
  10. BYTE *ProgAuthor    = "Paul Manias";
  11. BYTE *ProgDate      = "August 1998";
  12. BYTE *ProgCopyright = "DreamWorld Productions (c) 1998.  Freely distributable.";
  13. BYTE *ProgShort     = "Demonstration of the colours module.";
  14.  
  15. struct GScreen  *screen     = NULL;
  16. struct Restore  *restore    = NULL;
  17. struct JoyData  *joydata    = NULL;
  18. struct Picture  *background = NULL;
  19. struct Module   *ColoursMod = NULL;
  20. APTR COLBase;
  21.  
  22. struct FileName BackFile = { ID_FILENAME, "GMS:demos/data/PIC.Green" };
  23.  
  24. void Demo(void);
  25.  
  26. /***************************************************************************/
  27.  
  28. void main(void) {
  29.   if (ColoursMod = OpenModule(MOD_COLOURS,"colours.mod")) {
  30.      COLBase = ColoursMod->ModBase;
  31.  
  32.    if (background = Load(&BackFile, ID_PICTURE)) {
  33.     if (screen = Get(ID_SCREEN)) {
  34.        CopyStructure(background, screen);
  35.  
  36.      if (Init(screen,NULL)) {
  37.  
  38.       if (Copy(background->Bitmap,screen->Bitmap) IS ERR_OK) {
  39.  
  40.        if (joydata = Get(ID_JOYDATA)) {
  41.           joydata->Port = 1;     /* Forces mouse control */
  42.  
  43.         if (Init(joydata, NULL)) {
  44.            Display(screen); 
  45.            Demo();
  46.         }
  47.        }
  48.       }
  49.      }
  50.     }
  51.    }
  52.   }
  53.   Free(screen);
  54.   Free(joydata);
  55.   Free(background);
  56.   Free(ColoursMod);
  57. }
  58.  
  59. /***************************************************************************/
  60.  
  61. LIBFUNC void LightPen(mreg(__a0) struct Bitmap *Bitmap, mreg(__d1) WORD X, mreg(__d2) WORD Y)
  62. {
  63.    LightenPixel(Bitmap,X,Y,20);
  64. }
  65.  
  66. LIBFUNC void LightPen2(mreg(__a0) struct Bitmap *Bitmap, mreg(__d1) WORD X, mreg(__d2) WORD Y)
  67. {
  68.    LightenPixel(Bitmap,X,Y,15);
  69. }
  70.  
  71. void Demo(void)
  72. {
  73.    WORD XCoord = screen->Width/2;
  74.    WORD YCoord = screen->Height/2;
  75.    struct HSV HSV;
  76.    WORD Method = NULL;
  77.    WORD held = FALSE;
  78.  
  79.    ConvertRGBToHSV(DecRGB(100,90,30),&HSV);
  80.    DPrintF("RGBToHSV:","$%.8x = Hue: %d, Sat: %d, Val %d",DecRGB(100,90,30),HSV.Hue,HSV.Sat,HSV.Val);
  81.    DPrintF("Brightness:","%d",CalcBrightness(DecRGB(100,90,30)));
  82.  
  83.    ConvertRGBToHSV(DecRGB(75,150,105),&HSV);
  84.    DPrintF("RGBToHSV:","$%.8x = Hue: %d, Sat: %d, Val %d",DecRGB(75,150,105),HSV.Hue,HSV.Sat,HSV.Val);
  85.    DPrintF("Brightness:","%d",CalcBrightness(DecRGB(75,150,105)));
  86.  
  87.    ConvertRGBToHSV(DecRGB(80,160,255),&HSV);
  88.    DPrintF("RGBToHSV:","$%.8x = Hue: %d, Sat: %d, Val %d",DecRGB(80,160,255),HSV.Hue,HSV.Sat,HSV.Val);
  89.    DPrintF("Brightness:","%d",CalcBrightness(DecRGB(80,160,255)));
  90.  
  91.    SetRGBPen(screen->Bitmap,0xffffff);
  92.    SetPenShape(screen->Bitmap,PSP_CIRCLE,3);
  93.  
  94.    do
  95.    {
  96.      Query(joydata);
  97.      XCoord += joydata->XChange;
  98.      YCoord += joydata->YChange;
  99.      if (XCoord < 0) XCoord = screen->Width + XCoord;
  100.      if (YCoord < 0) YCoord = screen->Height + YCoord;
  101.      if (XCoord >= screen->Width)  XCoord = XCoord - screen->Width;
  102.      if (YCoord >= screen->Height) YCoord = YCoord - screen->Height;
  103.  
  104.      if (joydata->Buttons & JD_RMB) {
  105.         held = TRUE;
  106.      }
  107.      else if (joydata->Buttons & JD_LMB) {
  108.         if (Method IS 0) {
  109.            BlurArea(screen->Bitmap,XCoord,YCoord,40,40,50);
  110.         }
  111.         else if (Method IS 1) {
  112.            screen->Bitmap->PenUCPixel = &LightPen;
  113.            SetPenShape(screen->Bitmap,PSP_CIRCLE,3);
  114.            PenCircle(screen->Bitmap,XCoord,YCoord,30,FALSE);
  115.         }
  116.         else if (Method IS 2) {
  117.            screen->Bitmap->PenUCPixel = &LightPen;
  118.            PenCircle(screen->Bitmap,XCoord,YCoord,30,TRUE);
  119.         }
  120.         else if (Method IS 3) {
  121.            screen->Bitmap->PenUCPixel = &LightPen;
  122.            SetPenShape(screen->Bitmap,PSP_PIXEL,3);
  123.            PenRect(screen->Bitmap,XCoord,YCoord,30,30,FALSE);
  124.         }
  125.         else if (Method IS 4) {
  126.            screen->Bitmap->PenUCPixel = &LightPen2;
  127.            SetPenShape(screen->Bitmap,PSP_SQUARE,4);
  128.            PenEllipse(screen->Bitmap,XCoord,YCoord,20,40,FALSE);
  129.         }
  130.      }
  131.      else if (held IS TRUE) {
  132.         Method++;
  133.         if (Method > 4) Method = 0;
  134.         held = FALSE;
  135.      }
  136.  
  137.      LightenPixel(screen->Bitmap,XCoord,YCoord,50);
  138.  
  139.      WaitAVBL();
  140.    } while ((joydata->Buttons & (JD_RMB|JD_LMB)) != (JD_RMB|JD_LMB));
  141. }
  142.  
  143.